<?php

namespace app\api\controller;

use app\common\exception\BusinessException;
use think\response\Json;

class Ai extends Base
{
    /**
     * ocr
     * @return Json
     * @throws BusinessException
     */
    public function ocr()
    {
        // 外部参数
        $param = $this->request->param();

        // 验证规则
        $rule = [
            'url' => 'require|url',
        ];

        // 错误信息
        $errMsg = [];

        // 数据验证
        $valRel = $this->validate($param, $rule, $errMsg);
        if ($valRel !== true) {
            throw new BusinessException($valRel, 0);
        }

        // 提交查询
        $response = (new \app\api\logic\Ai())->ocr($param);

        // 返回
        return $this->response($response);
    }

    /**
     * speech
     * @return Json
     * @throws BusinessException
     */
    public function speech()
    {
        // 外部参数
        $param = $this->request->param();

        // 验证规则
        $rule = [
            'url' => 'require|url',
        ];

        // 错误信息
        $errMsg = [];

        // 数据验证
        $valRel = $this->validate($param, $rule, $errMsg);
        if ($valRel !== true) {
            throw new BusinessException($valRel, 0);
        }

        // 提交查询
        $response = (new \app\api\logic\Ai())->speech($param);

        // 返回
        return $this->response($response);
    }
}